package JFrame;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import Server.Socket.Client;


public class BuySell extends JFrame implements ActionListener{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	Client client;
	
	JPanel jPanel1 = new JPanel();
	
	//创建按钮对象
	JButton jButton1 = new JButton();
	JButton jButton2 = new JButton();
	
	//创新标签对象
	JLabel jLabel1 = new JLabel();
	JLabel jLabel2 = new JLabel();
	JLabel jLabel3 = new JLabel();
	JLabel jLabel4 = new JLabel();
	JLabel jLabel5 = new JLabel();
	
	
	//显示用户名
	JTextField jTextField1 = new JTextField();
	//显示交易股票期货代码
	JTextField jTextField2= new JTextField();
	//显示交易手数
	JTextField jTextField3 = new JTextField();
	//显示每手价格
	JTextField jTextField4 = new JTextField();
	//显示账户金额
	public static JTextField jTextField5 = new JTextField();
	
	//存放发往服务器端的内容
	String chatStr; 
	
	//创建布局变量
	GridLayout gridLayout1 = new GridLayout();

	public BuySell(){
		//初始化界面
		gridLayout1.setColumns(2);
		gridLayout1.setRows(6);
		jPanel1.setLayout(gridLayout1);
		jButton1.setText("买入");
		jButton1.addActionListener(this);
		jButton2.setText("卖出");
		jButton2.addActionListener(this);
		jLabel1.setText("用户名：");
		jLabel2.setText("股票期货代码");
		jLabel3.setText("交易手数");
		jLabel4.setText("每手价格");
		jLabel5.setText("账户余额：");
		jTextField1.setText("");
		jTextField2.setText("");
		jTextField3.setText("");
		jTextField4.setText("");
		jTextField5.setText("");
		jTextField5.setEditable(false);
		
		jPanel1.add(jButton1);
		jPanel1.add(jButton2);
		jPanel1.add(jLabel1);
		jPanel1.add(jTextField1);
		jPanel1.add(jLabel2);
		jPanel1.add(jTextField2);
		jPanel1.add(jLabel3);
		jPanel1.add(jTextField3);
		jPanel1.add(jLabel4);
		jPanel1.add(jTextField4);
		jPanel1.add(jLabel5);
		jPanel1.add(jTextField5);
		this.getContentPane().add(jPanel1,java.awt.BorderLayout.CENTER);
		
		this.setSize(400,400);
		this.setVisible(true);
		
		
	}
  
	public static void main(String[] args){
		BuySell buySell = new BuySell();
		buySell.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		client = new Client();
		chatStr = "`"+jTextField1.getText()+"`"+jTextField2.getText()+"`"+jTextField3.getText()+"`"+jTextField4.getText();
		if(e.getSource() == jButton1){
			client.buy(chatStr);
		}
		else if(e.getSource() == jButton2)
		{
			client.sell(chatStr);
		}
		
	}

}
